using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class VGUI : MonoBehaviour
{
    public void Init()
    {
        //如果VR有特殊逻辑则处理
        canvasStack = new Canvas[3];
        ValidateCanvas(VGUILayer.Battle);
    }
    
    public Canvas[] canvasStack;
    private bool ValidateCanvas(VGUILayer layer)
    {
        int index = layer.ToInt();
        if (canvasStack[index] == null)
        {
            //这个地方的Canvas应该是预制件加载,有调控的
            var canvasPrefab = "VGUICanvasBase".ToPrefab();
            var canvasGo = transform.UniqueChild(canvasPrefab).RemoveClone();
            var canvas = canvasGo.GetComponent<Canvas>();
            canvas.sortingOrder = layerDepth[layer];
            canvasStack[index] = canvas;
        }
        return true;
    }

    private bool ValidateVRCanvas(VGUILayer layer)
    {
        int index = layer.ToInt();
        if (canvasStack[index] == null)
        {
            //这个地方的Canvas应该是预制件加载,有调控的
            var canvasPrefab = "VGUICanvasBase".ToPrefab();
            var canvasGo = transform.UniqueChild(canvasPrefab).RemoveClone();
            var canvas = canvasGo.GetComponent<Canvas>();
            canvas.sortingOrder = layerDepth[layer];
            canvasStack[index] = canvas;
        }
        return true;
    }

    public static void Show()
    {
        //支持name or 枚举索引, 只是一个化简的方法
        //这里应该也是有级别的, 弹窗, box , 面板 , 遮罩, 并且限定是否点击屏蔽等

    }


    private static readonly Dictionary<VGUILayer, int> layerDepth = new Dictionary<VGUILayer, int>()
    {
        [VGUILayer.Battle] = 10,
        [VGUILayer.UI] = 20,
        [VGUILayer.System] = 100,
    };

}
/// <summary>
/// 这些成绩目前是
/// </summary>
public enum VGUILayer
{
    Battle = 0,
    UI = 1,
    System = 2,
    VR_World = 3
}
public static class VGUIExtension
{
    public static int ToInt(this VGUILayer layer) => (int)layer;
}
